package com.jackiechan.day14;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class LianXi {
    public static void main(String[] args) {
        System.out.print("请输入字符串:");
        String string = new Scanner(System.in).nextLine();
        show(string);
        show1(string);
    }

    private static void show1(String string) {
        Map<Character, Integer> map = new HashMap<>();
        char[] chars = string.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            Integer val = map.get(chars[i]);
            if (val == null) {
                map.put(chars[i], 1);
            } else {
                map.put(chars[i], ++val);
            }
        }
        System.out.println(map);
    }

    private static void show(String string) {
        Map<Character, Integer> map = new HashMap<>();
        char[] chars = string.toCharArray();
        int times;
        for (int i = 0; i < chars.length; i++) {
            if (map.containsKey(chars[i])) {
                times = map.get(chars[i]) + 1;
                map.put(chars[i], times);
            } else {
                map.put(chars[i], 1);
            }
        }
        System.out.println(map);
    }

}
